import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { APP_GUARD, APP_FILTER } from '@nestjs/core';

import { SysUserModule } from './sys/sys-user/sys-user.module';
import { SysRoleModule } from './sys/sys-role/sys-role.module';
import { AuthModule } from './auth/auth.module';
import { DateFormatDirective } from './common/directive/date-format.directive';
import { SysAuthorityModule } from './sys/sys-authority/sys-authority.module';
import { AuthenticationGuard } from './common/guard/authentication.guard';
import { BadRequestExceptionFilter } from './common/filter/bad-request-exception.filter';
import { UserModule } from './blog/user/user.module';
import { PostModule } from './blog/post/post.module';
import { CommentModule } from './blog/comment/comment.module';

@Module({
  providers: [
    {
      provide: APP_GUARD,
      useClass: AuthenticationGuard,
    },
    {
      provide: APP_FILTER,
      useClass: BadRequestExceptionFilter,
    },
  ],
  imports: [
    GraphQLModule.forRoot({
      typePaths: ['./**/*.schema.graphql'],
      schemaDirectives: {
        date: DateFormatDirective,
      },
      cors: {
        origin: ['http://localhost:3000'],
        credentials: true,
      },
      context: ({ req, res }) => {
        return {
          request: req,
          response: res,
        };
      },
      debug: false,
    }),
    SysUserModule,
    SysRoleModule,
    SysAuthorityModule,
    AuthModule,
    UserModule,
    PostModule,
    CommentModule,
  ],
})
export class AppModule {}
